function OS_Studio() {


	var musicVolume = 100;

	var soundVolume = 100;

	var musicList=null;
	
	var isRandom=false;
		
	var currentIndex=0;
	
    var musicCurrent=null;

	var musicNext=null;
	
	var len=0;
	
	var os=this;
	
	var changeTime=1000;
	
	var stop=false;
	
	this.setChangeTime=function(time){
	  changeTime=time;
	          
	}
	
	this.getChangeTime=function(){
	   return changeTime;
	}
	
	this.playBGM = function(mList, isRdom) {
	    
	    if(musicCurrent){
		      musicCurrent.stop();
		}
	  
	    musicList=mList;
	    len=musicList.length;
	    currentIndex=0;
	    musicCurrent=musicList[currentIndex];
		musicCurrent.play();
		isRandom=isRdom;
		stop=false;
	    for(var index=0;index<len;index++){
		musicList[index].setHandler("ended",this.playMusicList);
	}
	    musicCurrent.play();
	}

	this.pauseBGM = function() {
	    stop=true;
		  var temp=(new Date()).getTime();
		if (musicCurrent) {
			var intervalID = window.setInterval(function() {
				if ((new Date()).getTime()>=temp+changeTime) {
					window.clearInterval(intervalID);
					musicCurrent.pause();
					return;
				}
				musicCurrent.setVolume(musicVolume*(1-((new Date()).getTime()-temp)/changeTime));
			},
			30);

		}
	}

	this.stopBGM = function() {
        stop=true;
		  var temp=(new Date()).getTime();
		if (musicCurrent) {
			var intervalID = window.setInterval(function() {
				if ((new Date()).getTime()>=temp+changeTime) {
					window.clearInterval(intervalID);
					musicCurrent.stop();
					return;
				}
				musicCurrent.setVolume(musicVolume*(1-((new Date()).getTime()-temp)/changeTime));
			},
			30);

		}
	}
	this.resumeBGM = function() {
		if (musicCurrent) {
			musicCurrent.setVolume(0);
			musicCurrent.play();

			var intervalID = window.setInterval(function() {
				if (musicCurrent.getVolume() >= musicVolume) {
					window.clearInterval(intervalID);
					return;
				}
				var temp = musicCurrent.getVolume() + 1;
				musicCurrent.setVolume(temp);
			},
			30);


		}
	}

	this.changeBGM = function(mList,isRdom) {	  
	    musicList=mList;
	    len=musicList.length;
	    currentIndex=0;
		isRandom=isRdom;
	    for(var index=0;index<len;index++){
		musicList[index].setHandler("ended",this.playMusicList);
	}
	    musicNext=musicList[currentIndex];
		musicNext.setVolume(0);
		musicNext.play();
		stop=false;
		if(musicCurrent){
		    var temp=(new Date()).getTime();
			var intervalID = window.setInterval(function() {
				if ((new Date()).getTime()>=temp+changeTime) {
					if(musicCurrent)
					musicCurrent.stop();
					if(musicNext){
					musicNext.setVolume(musicVolume);
					}
					else{
					musicNext=musicList[currentIndex];
					musicNext.setVolume(musicVolume);
					}
					window.clearInterval(intervalID);
					musicCurrent = musicNext;
					musicNext = null;
					return;
				}
				if(musicNext)
				musicNext.setVolume(musicVolume*((new Date()).getTime()-temp)/changeTime);
				if(musicCurrent)
				musicCurrent.setVolume(musicVolume*(1-((new Date()).getTime()-temp)/changeTime));
			},
			30);

    }
		

	}

	this.getMusicVolume = function() {
		return musicVolume;
	}

	this.setMusicVolume = function(value) {
		musicVolume = value;
	}

	this.getSoundVolume = function() {
		return soundVolume;
	}

	this.setSoundVolume = function(value) {
		soundVolume = value;
	}

	this.playSound = function(os_Sound) {
		os_Sound.play();

	}	
	this.playMusicList=function(){
	   if(stop==false){
		if(isRandom){
	        currentIndex=Math.floor(Math.random()*len);
		}
		else{
			if(currentIndex<len-1){
				currentIndex=currentIndex+1;
				
			}
			else{
				currentIndex=0;
			}
			
		}
		musicCurrent=musicList[currentIndex];
		musicCurrent.play();
		}
	}
    





}
